define(["require",
	'config/appregister',
	"business/services/constant",
	"business/blogpost/service/blogHttp",
	"business/services/personCenterComp",
	"business/services/detailNavComp",
	"jquery", "domReady",
	"business/services/filter",
	"business/home/services/filterService",
	"business/services/commentComp",
], function(require, app, constant, httpServices) {
	app.controller('blogxqCtrl', function($scope, $http, $state, $stateParams,$rootScope,$sce) {
		if(!angular.isUndefined($stateParams.blogid)) {
			$scope.blogids = $stateParams.blogid;
			$scope.blogUserId=$stateParams.userId;
		}
		var blogid = $scope.blogids;
		var type = 0;

		//跳编辑博文
		$scope.modify = function() {
			$state.go("blogmod",{blogid:blogid});
		};
		//删除博文
		$scope.delblog = function() {
			var req = {
				type:'GET',
				uri:'del',
				data:{
					blogid:blogid
				}
			};
			httpServices.getmarkService(req).success(function(data) {
				if(!data)return;
				$scope.$apply(function() {
					if(data.code == 0) {
						console.log("删除成功");
						$state.go("bloglist");
					}else {
						console.log(data.msg);
					}
				});
			}).error(function() {
				console.log("删除博文请求失败");
			})
		};
		//弹出删除确认提示
		$scope.deleteblog = function() {
			$(".delTip").show();
		};
		//取消删除
		$scope.close = function() {
			$(".delTip").hide();
		};
		//有谁看过
		function getmark() {
			var req = {
				type:'GET',
				uri:'getMark',
				data:{
					fkId:blogid,
					type:'',
					count:10
				}
			};
			httpServices.getmarkService(req).success(function(data){
				if(!data)return;
				if(data.code==0) {
					console.log(data);
					$scope.$apply(function(){
						if(data.data.length<1) {
							$("#nullli").show();
						}else{
							$("#nullli").hide();
							$scope.mark = data.data;
						}						
					});
				}else {
					alert(data.msg)
				}
			}).error(function(){
				alert("请求mark失败");
			});
		};
		//痕迹跳转
		$scope.otherpage = function(id) {
//			$state.go("hasMainPage")
		}
		
		
		//跳上一篇下一篇
		$scope.jump = function(fpres) {
			if(!fpres)return;
			blogid = fpres;
			getblog();
			getxq();
			getmark();
		};
		getblog();
		getxq();
		getmark();
		
		//收藏
		$scope.getupdate = function() {
			var req = {
				type:'POST',
				uri:'update',
				data:{
					fkId:blogid,
					type:1
				}
			};
			httpServices.updateService(req).success(function(data){
				if(!data)return;
				console.log(data);
				if(data.code == 0) {
					$(".sc").html("已收藏").css({
						"background":"url(them/img/collectioned.png) 0px 2px no-repeat"
					});
				} else if(data.code == 112) {
					$(".sc").html("收藏").css({
						"background":"url(them/img/aiai.png) 0px 2px no-repeat"
					});
				};
			}).error(function(){
				alert("收藏请求失败");
			});
		};
		//跳转其他博文
		$scope.gotoother = function(theid){
			if(!theid)return;
			blogid = theid;
			getblog();
			getxq();
			getmark();
		};
		//查其他博文
		function getblog() {
			var req = {
				type:'GET',
				uri:'getOtherBlog',
				data:{
					pageNo:1,
					pageSize:10,
					all:false,
					type:0+","+2,
					blogId:blogid
				}
			};
			httpServices.getmarkService(req).success(function(data){
				if(!data)return;
				if(data.code==0) {
					$scope.other = data.data.list;
				}else {
					alert(data.msg);
				}
			}).error(function(){
				console.log("查其它博文失败");
			});
		};

		//中间菜单跳转
		$scope.gona = function(num) {
			if(num == 1) $state.go("homepage");
			if(num == 2) $state.go("myaccount");
			if(num == 3) $state.go("myMainPage");
			if(num == 4) $state.go("resume.posted");
		};



		//查详情
		function getxq() {
			if(!blogid)return alert('id为空');
			var req = {
				type:"GET",
				uri:"getInfo",
				data:{
					blogId:blogid,
					type:type
				}
			};
			httpServices.getblogHttpService(req).success(function(data){
				if(!data)return;
				console.log(data);
				$scope.$apply(function(){	
					if(data.code==0) {
							$sce.trustAsHtml(data.data.blog.introduction);
							$scope.title = data.data.blog.title;
							$scope.time = data.data.blog.createTime;
							$scope.nickname = data.data.blog.nickname;
							$scope.content = data.data.blog.introduction;
							$scope.fenlei = data.data.blog.dcList[0].detailCategory.dcName;
							$scope.comment = data.data.blog.commentCount;
							$scope.hot = data.data.blog.browseCount;
							$scope.labels = data.data.blog.labelList;
							$scope.flag = data.data.blog.flag;
							$scope.userId = data.data.blog.userId;
							
							if($scope.flag==true){
								$(".sc").html("已收藏").css({
									"background":"url(them/img/collectioned.png) 0px 2px no-repeat"
								});							
							}else {
								$(".sc").html("收藏").css({
									"background":"url(them/img/aiai.png) 0px 2px no-repeat"
								});
							};
							if(data.data.fpre) {
								$scope.fpre = data.data.fpre.title;
								$scope.fpres = data.data.fpre.blogId;
							} else {
								$scope.fpre = "暂无数据";
							}
							if(data.data.fnext) {
								$scope.next = data.data.fnext.title;
								$scope.fnexts = data.data.fnext.blogId;
							} else {
								$scope.next = "暂无数据";
							}							
					}else {
						alert(data.msg);
					}
				});
			}).error(function(){
				alert("详情请求失败");
			});
			
			//评论配置
			$scope.commentConf = {
            	isshowStar: false,
            	conf: {
                	id: $scope.blogids,
                	type: 1
            	}
       		};
//			$scope.commentConf = {
//				showStar: false,
//				url: constant.config.BASEURL_BLOG,
//				base: "elink_user/api/comment",
//				conf: {
//					id: blogid,
//					type: 0,
//					fkId:blogid,
//				},
//				uri: {
//					getTopComment: "getTopCommentsByFileId",
//					getSecComment: "getAllCommentsByTopId",
//					publish: "add",
//					reply: "addReply",
//					praise: "addPraise",
//					evaluate: "getEvaluateById",
//					recentComment: "getRecentComment"
//				}
//			};
		}

	});
});